<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Banner;
use app\common\model\Hospital as HospitalModel;
use app\common\model\Notice;

/**
 * 医院接口
 */
class Hospital extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 医院列表
     *
     */
    public function list()
    {
        $params = request()->param();
        extract($params);
        if (!$lat || !$lng) {
            $this->success('定位失败');
        }
        $hospital = new HospitalModel;
        if (isset($type) && $type == 1) {
            $hospital->where('title', '<>', '其他');
        }
        // if (!isset($sort) || !$sort) {
        //     $sort = 'asc';
        // }

        // if (isset($type) && $type != '') {
        //     $hospital->where('type', $type);
        // }
        // if (isset($level) && $level != '') {
        //     $hospital->where('level', $level);
        // }
        $hospital->where('city_id', $city_id);
        $hospital->where('status', 'normal');
        $list = $hospital->field(['*', distanceSql($lat, $lng)])->order('weigh desc')->paginate($size ?? 10);
        $this->success('请求成功', $list);
    }

    /**
     * 医院详情
     *
     */
    public function info()
    {
        $params = request()->param();
        extract($params);
        $hospital = new HospitalModel;
        $info =  $hospital->get($id);
        $this->success('请求成功', $info);
    }
}
